﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Vit.Common;
using Vit.Common.Providers;
using Vit.Web;
using Vit.Web.Models;
using Vit.Web.Providers.Data;

namespace Vit.Web.SqlProviders
{
    public class SqlDataSourceCategoryDataProvider : DbContextDataProvider<WebProvidersDb, DataSourceCategory>
    {
        protected override IQueryable<DataSourceCategory> OrderByDefault(IQueryable<DataSourceCategory> query)
        {
            return query.OrderBy(o => o.CategoryName);
        }

        public override object[] GetKeys(DataSourceCategory obj)
        {
            return new object[] { obj.CategoryName };
        }

        public override DataSourceCategory GetByKeys(params object[] ids)
        {
            if (ids == null || ids.Length != 1)
                return null;
            string key = ids[0].ToString();
            return db.DataSourceCategories.FirstOrDefault(o => o.CategoryName == key);
        }

        protected override bool IsCached
        {
            get
            {
                return true;
            }
        }
    }
}
